import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			String str = br.readLine().trim();
			if(str == null || str.isEmpty()) {
				break;
			}
			
			int n = Integer.parseInt(str);
			str = br.readLine();
			StringTokenizer sToken = new StringTokenizer(str, " ");
			int[] a = new int[n];
			for(int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(sToken.nextToken());
			}
			
			Mixture[][] mem = new Mixture[n][n];
			for(int i = 0; i < n; i++) {
				mem[i][i] = new Mixture(a[i], 0L);
				if(i + 1 < n) {
					mem[i][i + 1] = new Mixture((a[i] + a[i + 1]) % 100, a[i] * a[i + 1]);
				}
			}
			
			for(int k = 2; k < n; k++) {
				for(int i = 0; i < n && i + k < n; i++) {
					int start = i, end = i + k;
					long minSmoke = Long.MAX_VALUE;
					int col = 0;
					for(int cur = start; cur < end; cur++) {
						if(minSmoke > (mem[start][cur].color * mem[cur + 1][end].color) + mem[start][cur].smoke + mem[cur + 1][end].smoke) {
							minSmoke = (mem[start][cur].color * mem[cur + 1][end].color) + mem[start][cur].smoke + mem[cur + 1][end].smoke;
							col = (mem[start][cur].color + mem[cur + 1][end].color) % 100;
						}
					}
					mem[start][end] = new Mixture(col, minSmoke);
				}
			}
			System.out.println(mem[0][n - 1].smoke);
		}
	}
	
	private static class Mixture {
		int color;
		
		long smoke;
		
		public Mixture(int c, long s) {
			color = c;
			smoke = s;
		}
		
		public String toString() {
			return color + " " + smoke;
		}
	}

}
